package com.design.pattern.flyweight;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class LittleCarFlyWeightFactory {

    private static Map<String,CarFlyWeight> cars=new ConcurrentHashMap();

    public static CarFlyWeight get(String color){
       CarFlyWeight car=cars.get(color);
        if (null==car){
            car=new LittleConcreteFlyWeight();
            ((LittleConcreteFlyWeight)car).setColor(color);
            cars.put(color,car);
        }
        return car;
    }
    public static void add(LittleConcreteFlyWeight carFlyWeight){
        CarFlyWeight car=cars.get(carFlyWeight.getColor());
        if (null==car){

            cars.put(carFlyWeight.getColor(),carFlyWeight);
        }
    }
    public static void delete(LittleConcreteFlyWeight carFlyWeight){
        CarFlyWeight car=cars.get(carFlyWeight.getColor());
        if (null!=car){

            cars.remove(carFlyWeight.getColor(),carFlyWeight);
        }
    }
}
